const router = require('koa-router')(),
  spotslist=require('../models/spots');


router.prefix('/spots')

router.get('/', async function (ctx, next) {
    ctx.body=await spotslist.getSpots();
})

router.get('/all', async function (ctx, next) {
  ctx.body=await spotslist.getSpotsAll();
})

router.get('/byid', async function (ctx, next) {
    const {id}=ctx.query
    ctx.body=await spotslist.getSpotById(id);
})

router.get('/detail', async function (ctx, next) {
  const {id}=ctx.query
  ctx.body=await spotslist.getSpotByIdDetail(id);
})

router.get('/byname', async function (ctx,next){
  const {name}=ctx.query
  ctx.body=await spotslist.getSpotByName(name);
  // ctx.body=name;
})

router.get('/addgone', async function (ctx,next){
  const {spotid,userid,time}=ctx.query
  ctx.body=await spotslist.addSpotGone(spotid,userid,time);
})

router.get('/getgone', async function (ctx,next){
  const {userid}=ctx.query
  ctx.body=await spotslist.getSpotGone(userid);
})

router.get('/check', async function (ctx,next){
  const {spotid,userid}=ctx.query
  ctx.body=await spotslist.checkGone(spotid,userid);
})

router.get('/rate', async function (ctx, next) {
  const {spotid,userid,value}=ctx.query
  console.log(spotid,userid,value)
  ctx.body=await spotslist.rate(userid,spotid,value);
})

module.exports = router